package com.atguigu.gmall.user.service.impl;

import com.atguigu.gmall.common.util.MD5;
import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.model.user.UserInfo;
import com.atguigu.gmall.user.mapper.UserAddressMapper;
import com.atguigu.gmall.user.mapper.UserInfoMapper;
import com.atguigu.gmall.user.service.UserInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: 李旭
 * @create: 2021-09-06 14:21
 **/
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private UserAddressMapper userAddressMapper;

    //校验用户名或密码是否正确
    @Override
    public UserInfo checkUserInfo(UserInfo userInfo) {
        return userInfoMapper.selectOne(new QueryWrapper<UserInfo>()
          .eq("login_name",userInfo.getLoginName())
          .eq("passwd", MD5.encrypt(userInfo.getPasswd())));
        //MD5 穷举法
        // md5 自定义 咱们公司自己写的
    }
    //查询当前用户的收货地址集合
    @Override
    public List<UserAddress> findUserAddressList(String userId) {
        return userAddressMapper.selectList(
                new QueryWrapper<UserAddress>().eq("user_id",userId)
        );
    }

    public static void main(String[] args) {
        System.out.println(MD5.encrypt("123"));
    }
}
